package com.gameapplet.util.encrypte;

import com.gameapplet.util.AESUtil;
import org.bouncycastle.jcajce.provider.asymmetric.RSA;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class test {

    public static void main(String[] args) throws Exception{
//        RSAUtils.getKeys();
//        String s = RSAUtils.encryptByPublicKey("1254");
//        System.out.println("公钥加密后："+s);
//        String de = RSAUtils.decryptByPrivateKey(s);
//        System.out.println("解密后："+de);
//
//        String AESkey = AESUtils.generateKey();
//        System.out.println("AESkey:"+AESkey);
//        String AESen = AESUtils.encryptData(AESkey,"8888");
//        System.out.println("AESen:"+AESen);
//        String AESde = AESUtils.decryptData(AESkey,AESen);
//        System.out.println("AES解密后："+AESde);
//        RSAUtils.getKeys();


//        String AESKey = AESUtils.generateKey();
//        String AESDate = AESUtils.encryptData(AESKey,"1");
//        String RSADate = RSAUtils.encryptByPublicKey("{'publickey':'"+AESKey+"','date':'"+AESDate+"'}");
//        System.out.println("RSADateJson:"+RSADate);

//        Date day=new Date();
//        System.out.println(day);
//        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
//        System.out.println(df.format(day));


                String xmlString = "<xml>"
                        + "<appid><![CDATA[wx2421b1c4370ec43b]]></appid>"
                        + "<attach><![CDATA[支付测试]]></attach>"
                        + "<bank_type><![CDATA[CFT]]></bank_type>"
                        + "<fee_type><![CDATA[CNY]]></fee_type>"
                        + "<total_fee>1</total_fee>"
                        + "</xml>";
                //去掉前后的xml标签
                xmlString = xmlString.replaceAll("</?xml>", "");
                System.out.println(xmlString);
                //匹配一段一段这样的数据   <attach><![CDATA[支付测试]]></attach>
                Pattern pattern = Pattern.compile("<.*?/.*?>");
                Matcher matcher = pattern.matcher(xmlString);
                //配置是否包含<![CDATA[CNY]]> CDATA 包裹的数据
                Pattern pattern2 = Pattern.compile("!.*]");
                Map<String, String> map = new HashMap<>();
                while(matcher.find()) {
                    //获取键
                    String key = matcher.group().replaceAll(".*/", "");
                    key = key.substring(0, key.length() - 1);
                    Matcher matcher2 = pattern2.matcher(matcher.group());
                    String value = matcher.group().replaceAll("</?.*?>", "");
                    //获取值
                    if(matcher2.find() && !value.equals("DATA")) {
                        value = matcher2.group().replaceAll("!.*\\[", "");
                        value = value.substring(0, value.length() - 2);
                    }
                    map.put(key, value);
                }
                System.out.println(map.size());
                for(String m:map.keySet()){
                    System.out.println(map.get(m));
                }




//        String RSADE = RSAUtils.decryptByPrivateKey(RSADate);
//        System.out.println("RSA解密："+RSADE);
//        String[] s = RSADE.split(":");
//        System.out.println("AES解密:"+AESUtils.decryptData(s[0],s[1]));
//        System.out.println(Integer.parseInt("-1"));
//        System.out.println(Integer.parseInt("-1124"));
//        System.out.println(Integer.parseInt("0"));
//        System.out.println(Integer.parseInt("13123124"));
//        System.out.println(Integer.parseInt("1"));


    }

}
